<?php

class MEvent extends CI_Model{

	public function __construct()
	    {
	        parent::__construct();
	    }
	
	
	function getEvent($id){
	    $data = array();
	    $this->db->where('event_id',id_clean($id));
	    $this->db->limit(1);
	    $Q = $this->db->get('event');
	    if ($Q->num_rows() > 0){
	      $data = $Q->row_array();
	    }
	
	    $Q->free_result();    
	    return $data;    
	 }
	
	function getEventPath($path){
	    $data = array();
	    $this->db->where('path',db_clean($path));
	    $this->db->where('activate', 1);
	    $this->db->limit(1);
	    $Q = $this->db->get('event');
	    if ($Q->num_rows() > 0){
	      $data = $Q->row_array();
	    }
	
	    $Q->free_result();    
	    return $data;    
	 }
		
	 function getAllEvents(){
	     $data = array();
	     $this->db->order_by("date_created", "desc");
	     $Q = $this->db->get('event');
	     if ($Q->num_rows() > 0){
	       foreach ($Q->result_array() as $row){
	         $data[] = $row;
	       }
	    }
	    $Q->free_result();  
	    return $data; 
	 }
	
 	function getAllActiveEvents(){
	     $data = array();
	     $this->db->where('activate', 1);
	     $this->db->order_by("date_created", "desc");
	     $Q = $this->db->get('event');
	     if ($Q->num_rows() > 0){
	       foreach ($Q->result_array() as $row){
	         $data[] = $row;
	       }
	    }
	    $Q->free_result();  
	    return $data; 
	 }
		
	 function addEvent(){
		$data = array( 
			'title' => db_clean($_POST['title']),
			'path' => db_clean($_POST['path']),
			'shortdesc' => db_clean($_POST['shortdesc']),
			'longdesc' => $_POST['longdesc'],
			'uid' => db_clean($_SESSION['uid']),
			'activate' => db_clean($_POST['activate'])
		);
		$this->db->set('date_created', 'NOW()', FALSE);
		$this->db->insert('event', $data);	 
	 }
	 
	 function updateEvent(){
		$data = array( 
			'title' => db_clean($_POST['title']),
			'path' => db_clean($_POST['path']),
			'shortdesc' => db_clean($_POST['shortdesc']),
			'longdesc' => $_POST['longdesc'],
			'uid' => db_clean($_SESSION['uid']),
			'activate' => db_clean($_POST['activate'])
		
		);
	
	 	$this->db->where('event_id', id_clean($_POST['event_id']));
	 	$this->db->set('date_modified', 'NOW()', FALSE);
		$this->db->update('event', $data);	
	 
	 }
	 function inactiveEvent($id){
	 	$data = array('activate' => 0);
	 	$this->db->where('event_id', id_clean($id));
		$this->db->update('event', $data);	
	 }
	 
	 function deleteEvent($id){
	 	$this->db->where('event_id', id_clean($id));
		$this->db->delete('event');	
	 }
	 
	
}

?>